Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conflict between cancelled vs. next_payment dates for pending-cancel #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Mar 28, 2024

#278 introduced cancelled_date as an importable column, and also fixed some behavior which was preventing end_date from being properly applied to imported subscriptions. However, it also introduced a potential conflict between cancelled_date and next_payment dates for imported subscriptions with a pending-cancel status.

Some preexisting logic in master forces a next_payment date for pending-cancel subscriptions, which becomes the end date for those subscriptions after being imported. However, if a cancelled_date is also set for these subscriptions, importing will fail with an error as pending-cancel subscriptions can't have a cancelled_date that occurs before next_payment.

This PR proposes a fix to not force next_payment for these subscriptions. However, pending-cancel subscriptions do need to ultimately have an end_date, otherwise they'll essentially continue to be active indefinitely. So the proposed change checks pending-cancel subs for a future next_payment date, and if it exists, moves it to the end_date instead and clears next_payment to avoid the import error. In local testing this resulted in imported pending-cancel subscriptions with the same date behavior/data schema as subscriptions that were manually moved to pending-cancel status via admin or subscriber action.

If the subscription to be imported lacks both an end_date and a next_payment date, or both are in the past, the importer will continue to throw an error as it did before in this scenario.

To test:

  1. On master, import a subscription that has both a cancelled_date and an end_date. Here's some sample data you could use to import (replace <product ID> with a valid product ID on your test site):
customer_id,customer_email,customer_username,customer_password,billing_first_name,billing_last_name,billing_address_1,billing_address_2,billing_city,billing_state,billing_postcode,billing_country,billing_email,billing_phone,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_city,shipping_state,shipping_postcode,shipping_country,subscription_status,start_date,trial_end_date,next_payment_date,cancelled_date,end_date,billing_period,billing_interval,order_items,coupon_items,fee_items,tax_items,cart_discount,cart_discount_tax,order_shipping,order_shipping_tax,order_total,order_tax,order_currency,shipping_method,download_permissions,order_notes,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,customer_note
,[email protected],[email protected],,,,,,,,,,[email protected],,,,,,,,,,,wc-pending-cancel,2024-03-15 08:40:00,,,2024-03-17 13:38:00,2025-03-15 08:40:00,year,1,product_id:<product ID>|name:|quantity:1|subtotal_tax:0|subtotal:60|tax:0|total:60,,,,,,,,60,,,,1,,,Manual Renewal,,,
  1. Observe an error upon import:
Row #1 from CSV failed to import with error/s:
1. Subscription #1111: The cancelled date must occur after the next payment date.
  1. Apply the patch in this branch and repeat.
  2. Confirm that the subscription is imported with the correct "Pending cancellation" status, and the correct cancellation and end dates:
Screenshot 2024-03-28 at 1 41 24 PM
  1. Edit the CSV data and move the end_date value to the next_payment_date column instead. Import and confirm that it successfully imports with the same results as in step 4.
  2. Edit the CSV once more and include both a future end_date and a different next_payment_date value. Import and confirm that it successfully imports with the end date intact, but discards the next payment date.

@dkoo dkoo added bug Needs Review Ready for review labels Mar 28, 2024
@dkoo dkoo self-assigned this Mar 28, 2024
@dkoo
Copy link
Contributor Author

dkoo commented May 8, 2024

@james-allan as the person who helped me with the last couple of PRs, could I ask for a review of this one too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Review Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant